package cc.verywell.pureblock.msg.p2p;

import cc.verywell.pureblock.func.FuncTimelog;

/**
* 
* <p>用ping和pong，计算出两地的时间差，以及此时间差的±公差</p>
* 
* Copyright © 2019 TanYaqiu. All rights reserved.
* @author TanYaqiu 
* @address flat 601
* @date 2019年3月19日 下午9:36:19
*/
public interface P2pTimelog extends FuncTimelog {
	//public void initTime(long remoteSentTime,long localReceiveTime);
	//public long getRemoteTimeOffset();
//	/**
//	 * 请马上返回sentTimePing，以尽量缩小公差;
//	 * when we sent timePing , we mark this, for when we received pong we can getSentTimePing();
//	 */
//	public void sentTimePing(long localTimeSent);
//	/**
//	 * 由 P2pTimelog 内部处理这个函数;
//	 * @return last time ping we stored, if return -1,then no ping sent.
//	 */
//	public long getSentTimePing();
	/**
	 * <p>lastTimePeriod = remoteTimeReceive - localTimeSent</p>
	 * <p>a sample tolerance algorithm is remoteTimeTolerance=[(lastTimePeriod)+(localTimeReceive-remoteTimeSent)]/2;</p>
	 * <p>a sample offset algorithm is remoteTimeOffset=(remoteTimeSent + remoteTimeTolerance)-localTimeReceive;</p>
	 * @param lastTimePeriod remote sent us getLastTimePongPeriod();
	 * @param remoteTimeSent they sent to us;
	 * @param localTimeReceive what time we received ping；
	 */
	public void receivedTimePing(long lastTimePeriod,long remoteTimeSent,long localTimeReceive);
	/**
	 * <p>getLastTimePing() = localTimeSent;</p>
	 * <p>lastTimePeriod = (remoteTimeReceive - localTimSent),remoteTimeSent,localTimeReceive. <br>when we have the 3 variables, we can calculate remote time offset and tolerance.</p>
	 * <p>after progress ,we need let getSentTimePing()=-1;</p>
	 * @param lastTimePeriod  = lastTimePeriod = (remoteTimeReceive - localTimSent);
	 * @param remoteTimeSent = remoteTimeSent;
	 * @param localTimeReceive = localTimeReceive;
	 */
	public void receivedTimePong(long lastTimePeriod,long localTimeSent,long remoteTimeSent,long localTimeReceive);
	/**
	 * @return  last local receive time - last remote sent time;
	 */
	public long getLastTimePeriod();
	/**
	 * <p>返回远程和本地时差的±公差，时差返回函数是{@link #getRemoteTimeOffset()}</p>
	 * Copyright © 2019 TanYaqiu. All rights reserved.
	 * @return remote time ±Tolerance , a sample tolerance algorithm is remoteTimeTolerance=[(localTimeReceive-remoteTimeSent)+(remoteTimeReceive-localTimeSent)]/2;
	 * <br>sometimes return -1 if tolerace not ready.
	 */
	public long getRemoteTimeTolerance();
	/**
	 * 估算往返需要的时间;
	 * @return -1表示没有估算，此值只反映网络质量，请加上[运算复杂度]以估算所需的总时间;
	 */
	public long getP2PtimeOut();
}